<!DOCTYPE HTML>
<html lang="zh-hans" >
    <!-- Start book Python基础 -->
<!-- Start book Python基础 -->
    <head>
        <!-- head:start -->
<!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>字典的基本使用 | Python基础</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        <meta name="author" content="姜伟">
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-prism/prism.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../chapter02/section01.html" />
    
    
    <link rel="prev" href="../chapter01.html" />
    

        <!-- head:end -->
<!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
<!-- body:start -->
        
    <div class="book"
        data-level="2"
        data-chapter-title="字典的基本使用"
        data-filepath="chapter02/README.md"
        data-basepath=".."
        data-revision="Sun Feb 09 2020 19:04:23 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        学习目标
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter01.html">
            
                
                    <a href="../chapter01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        元组的使用
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2" data-path="chapter02/index.html">
            
                
                    <a href="../chapter02/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        字典的基本使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="chapter02/section01.html">
            
                
                    <a href="../chapter02/section01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        字典的增删改查
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="chapter02/section02.html">
            
                
                    <a href="../chapter02/section02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        字典的遍历
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="chapter03.html">
            
                
                    <a href="../chapter03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        集合的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4" data-path="chapter04.html">
            
                
                    <a href="../chapter04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        转换相关
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5" data-path="chapter05.html">
            
                
                    <a href="../chapter05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        通用方法
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本书使用 GitBook 发布
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >Python基础</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x5B57;&#x5178;&#x4ECB;&#x7ECD;">&#x5B57;&#x5178;&#x4ECB;&#x7ECD;</h1>
<h2 id="&#x4E00;&#x3001;&#x5217;&#x8868;&#x7684;&#x7F3A;&#x70B9;">&#x4E00;&#x3001;&#x5217;&#x8868;&#x7684;&#x7F3A;&#x70B9;</h2>
<p>&#x5F53;&#x5B58;&#x50A8;&#x7684;&#x6570;&#x636E;&#x8981;&#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x3001;&#x5220;&#x9664;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6211;&#x4EEC;&#x4E00;&#x822C;&#x4F7F;&#x7528;&#x5217;&#x8868;&#xFF0C;&#x4F46;&#x662F;&#x5217;&#x8868;&#x6709;&#x65F6;&#x4F1A;&#x9047;&#x5230;&#x4E00;&#x4E9B;&#x9EBB;&#x70E6;&#x3002;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x4FDD;&#x5B58;&#xFF0C;&#x59D3;&#x540D;&#x3001;&#x6027;&#x522B;&#x3001;&#x804C;&#x4E1A;</span>
nameList = [<span class="hljs-string">&apos;xiaoZhang&apos;</span>, <span class="hljs-string">&apos;&#x7537;&apos;</span>, <span class="hljs-string">&apos;&#x6728;&#x5320;&apos;</span>];

<span class="hljs-comment"># &#x5F53;&#x4FEE;&#x6539;&#x804C;&#x4E1A;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x9700;&#x8981;&#x8BB0;&#x5FC6;&#x5143;&#x7D20;&#x7684;&#x4E0B;&#x6807;</span>
nameList[<span class="hljs-number">2</span>] = <span class="hljs-string">&apos;&#x94C1;&#x5320;&apos;</span>  

<span class="hljs-comment"># &#x5982;&#x679C;&#x5217;&#x8868;&#x7684;&#x987A;&#x5E8F;&#x53D1;&#x751F;&#x4E86;&#x53D8;&#x5316;&#xFF0C;&#x6DFB;&#x52A0;&#x5E74;&#x9F84;</span>
nameList = [<span class="hljs-string">&apos;xiaoWang&apos;</span>, <span class="hljs-number">18</span>, <span class="hljs-string">&apos;&#x7537;&apos;</span>,  <span class="hljs-string">&apos;&#x94C1;&#x5320;&apos;</span>]

<span class="hljs-comment"># &#x6B64;&#x65F6;&#x5C31;&#x9700;&#x8981;&#x8BB0;&#x5FC6;&#x65B0;&#x7684;&#x4E0B;&#x6807;&#xFF0C;&#x624D;&#x80FD;&#x5B8C;&#x6210;&#x540D;&#x5B57;&#x7684;&#x4FEE;&#x6539;</span>
nameList[<span class="hljs-number">3</span>] = <span class="hljs-string">&apos;xiaoxiaoWang&apos;</span>
</code></pre>
<p><strong>&#x6709;&#x6CA1;&#x6709;&#x65B9;&#x6CD5;&#xFF0C;&#x65E2;&#x80FD;&#x5B58;&#x50A8;&#x591A;&#x4E2A;&#x6570;&#x636E;&#xFF0C;&#x8FD8;&#x80FD;&#x5728;&#x8BBF;&#x95EE;&#x5143;&#x7D20;&#x7684;&#x5F88;&#x65B9;&#x4FBF;&#x5C31;&#x80FD;&#x591F;&#x5B9A;&#x4F4D;&#x5230;&#x9700;&#x8981;&#x7684;&#x90A3;&#x4E2A;&#x5143;&#x7D20;&#x5462;&#xFF1F;</strong></p>
<p>&#x7B54;&#xFF1A;</p>
<blockquote>
<p>&#x5B57;&#x5178;</p>
</blockquote>
<h2 id="&#x4E8C;&#x3001;&#x5B57;&#x5178;&#x7684;&#x4F7F;&#x7528;">&#x4E8C;&#x3001;&#x5B57;&#x5178;&#x7684;&#x4F7F;&#x7528;</h2>
<p>&#x5B9A;&#x4E49;&#x5B57;&#x5178;&#x7684;&#x683C;&#x5F0F;&#xFF1A;<strong>{&#x952E;1:&#x503C;1, &#x952E;2:&#x503C;2, &#x952E;3:&#x503C;3, ..., &#x952E;n:&#x503C;n}</strong></p>
<p>&#x53D8;&#x91CF;info&#x4E3A;&#x5B57;&#x5178;&#x7C7B;&#x578B;&#xFF1A;</p>
<pre><code class="lang-python">info = {<span class="hljs-string">&apos;name&apos;</span>:<span class="hljs-string">&apos;&#x73ED;&#x957F;&apos;</span>, <span class="hljs-string">&apos;id&apos;</span>:<span class="hljs-number">100</span>, <span class="hljs-string">&apos;sex&apos;</span>:<span class="hljs-string">&apos;f&apos;</span>, <span class="hljs-string">&apos;address&apos;</span>:<span class="hljs-string">&apos;&#x5730;&#x7403;&#x4E9A;&#x6D32;&#x4E2D;&#x56FD;&#x4E0A;&#x6D77;&apos;</span>}
info[<span class="hljs-string">&apos;name&apos;</span>]  <span class="hljs-comment"># &#x5B57;&#x5178;&#x4F7F;&#x7528;&#x952E;&#x6765;&#x83B7;&#x53D6;&#x5BF9;&#x5E94;&#x7684;&#x503C;</span>
</code></pre>
<p>&#x8BF4;&#x660E;&#xFF1A;</p>
<ul>
<li>&#x5B57;&#x5178;&#x548C;&#x5217;&#x8868;&#x4E00;&#x6837;&#xFF0C;&#x4E5F;&#x80FD;&#x591F;&#x5B58;&#x50A8;&#x591A;&#x4E2A;&#x6570;&#x636E;</li>
<li>&#x5217;&#x8868;&#x4E2D;&#x627E;&#x67D0;&#x4E2A;&#x5143;&#x7D20;&#x65F6;&#xFF0C;&#x662F;&#x6839;&#x636E;&#x4E0B;&#x6807;&#x8FDB;&#x884C;&#x7684;&#xFF1B;&#x5B57;&#x5178;&#x4E2D;&#x627E;&#x67D0;&#x4E2A;&#x5143;&#x7D20;&#x65F6;&#xFF0C;&#x662F;&#x6839;&#x636E;&apos;&#x540D;&#x5B57;&apos;&#xFF08;&#x5C31;&#x662F;&#x5192;&#x53F7;:&#x524D;&#x9762;&#x7684;&#x90A3;&#x4E2A;&#x503C;&#xFF0C;&#x4F8B;&#x5982;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#x7684;&apos;name&apos;&#x3001;&apos;id&apos;&#x3001;&apos;sex&apos;&#xFF09;</li>
<li>&#x5B57;&#x5178;&#x7684;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x7531;2&#x90E8;&#x5206;&#x7EC4;&#x6210;&#xFF0C;&#x952E;:&#x503C;&#x3002;&#x4F8B;&#x5982; &apos;name&apos;:&apos;&#x73ED;&#x957F;&apos; ,&apos;name&apos;&#x4E3A;&#x952E;&#xFF0C;&apos;&#x73ED;&#x957F;&apos;&#x4E3A;&#x503C;</li>
<li>&#x952E;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x6570;&#x5B57;&#x3001;&#x5E03;&#x5C14;&#x503C;&#x3001;&#x5E03;&#x5C14;&#x503C;&#x3001;&#x5143;&#x7EC4;&#x7B49;<span style="color:red;font-weight:700">&#x4E0D;&#x53EF;&#x53D8;&#x6570;&#x636E;&#x7C7B;&#x578B;</span>&#xFF0C;&#x4F46;&#x662F;&#x4E00;&#x822C;&#x4E60;&#x60EF;&#x4F7F;&#x7528;&#x5B57;&#x7B26;&#x4E32;</li>
<li><span style="font-weight:700">&#x6BCF;&#x4E2A;&#x5B57;&#x5178;&#x91CC;&#x7684;key&#x90FD;&#x662F;&#x552F;&#x4E00;&#x7684;&#xFF0C;&#x5982;&#x679C;&#x51FA;&#x73B0;&#x4E86;&#x591A;&#x4E2A;key,&#x540E;&#x9762;&#x7684;value&#x4F1A;&#x8986;&#x76D6;&#x524D;&#x4E00;&#x4E2A;key&#x5BF9;&#x5E94;&#x7684;value.</span></li>
</ul>
<p>&#x5728;&#x4E60;&#x60EF;&#x4E0A;&#xFF1A;</p>
<ul>
<li>&#x5217;&#x8868;&#x66F4;&#x9002;&#x5408;&#x4FDD;&#x5B58;&#x591A;&#x4E2A;&#x5546;&#x54C1;&#x3001;&#x591A;&#x4E2A;&#x59D3;&#x540D;&#x3001;&#x591A;&#x4E2A;&#x65F6;&#x95F4;&#xFF0C;&#x8FD9;&#x6837;&#x7684;&#x76F8;&#x4F3C;&#x6570;&#x636E;&#xFF1B;</li>
<li>&#x5B57;&#x5178;&#x66F4;&#x9002;&#x5408;&#x4FDD;&#x5B58;&#x4E00;&#x4E2A;&#x5546;&#x54C1;&#x7684;&#x4E0D;&#x540C;&#x4FE1;&#x606F;&#x3001;&#x4E00;&#x4E2A;&#x4EBA;&#x7684;&#x4E0D;&#x540C;&#x4FE1;&#x606F;&#xFF0C;&#x8FD9;&#x6837;&#x7684;&#x4E0D;&#x540C;&#x6570;&#x636E;&#x3002;</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../chapter01.html" class="navigation navigation-prev " aria-label="Previous page: 元组的使用"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../chapter02/section01.html" class="navigation navigation-next " aria-label="Next page: 字典的增删改查"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-copy-code-button/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"prism":{},"splitter":{},"copy-code-button":{},"toggle-chapters":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
<!-- body:end -->
    </body>
    <!-- End of book Python基础 -->
<!-- End of book Python基础 -->
</html>
